﻿//Start of utilities
//return the length of a string

function Len(string){
    var Len = string.length;
    return Len;
}

//return a number of characters from the
//     right side of a string

function Right(string,count){
	var Start = Number(string.length) - Number(count);
	var End = Number(string.length);
	var Right = string.substring(Start,End);
	return Right;
}

//return a number of characters from the
//     left side of a string

function Left(string,count){
	var End = Number(count);
	var Left = string.substring(0,End);
	return Left;
}

//return an array of string bits from a 
//     string

function Parse(string,deliminator){
	var Parse = string.split(deliminator);
	return Parse;
}

//find an instance of a characters in a 
//     string and return the integer position

function inStr(start,string1,string2){


    	if(start > 0){
    		string1 = Right(string1,string1.length - start)
    	}
    	var inStr = string1.indexOf(string2);
    	return inStr + 1;
}




function DelListItem(Objectname,ItemValue){
    /*remove an item from a listbox
    Objectname is formname.listname format
    ItemValue is item number (list is 0 based first item = 0 second item = 1 and so on)
    Usage DelListItem(form1.list1,1) this will remove the second item from list1 in form1
    */
    var listcount = Objectname.length-1; //get the count of list items

    if(listcount < ItemValue){ //if you asked for a nonexisting item
	    var DelListItem = 'false'; //set the response to false
	    return DelListItem; //return OOPS
    }

    else{ //the item is valid remove it
	    Objectname.options[ItemValue] = null; //set the item display text and value to nothing
	    var DelListItem = 'true'; //set the response to true
	    return DelListItem; //return OK
    }
}


function AddList(Objectname,ItemValue,DisplayText){
/*insert a new item into a listbox
Objectname is formname.listname format
ItemValue is value passed on submit
DisplayText is text shown in listbox
Usage AddList(form1.list1,'new text','5') this will add a new option to list1 in form1 it will display 'new text' and pass a value of 5 on submit
*/
	var listcount = Objectname.length; //listcount will give you the next open listindex number
	
	Objectname.options[Number(listcount)] = new Option(DisplayText,ItemValue); //new option will let you insert the (display text,list value)
	var AddList = 'true'; //set the response to true
	return AddList; //return OK
}


function ClearList(Objectname){
    /*clears ALL items form listbox
    Objectname is formname.listname format
    Usage ClearList(form1.list1) this will remove ALL items from list1 in form1 the list is now blank
    */
	Objectname.options.length = 0; //set ALL item display text and values to nothing
	var AddList = 'true'; //set the response to true
	return AddList; //return OK
}

function Lock(evt)
{
    return false;
}         
//End of utilities